<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="130px"
    >
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="creditCode">
        <el-input
          v-model="queryParams.creditCode"
          placeholder="请输入统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['common:cooperator:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['common:cooperator:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['common:cooperator:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['common:cooperator:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="cooperatorList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="名称" align="center" prop="enterpriseName" />
      <!--      <el-table-column label="企业简称" align="center" prop="enterpriseAbbreviation" />-->
      <el-table-column
        label="统一社会信用代码"
        align="center"
        prop="creditCode"
      />
      <el-table-column label="企业类型" align="center" prop="enterpriseType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.common_enterprise_type"
            :value="scope.row.enterpriseType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="资质等级"
        align="center"
        prop="qualificationLevel"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.common_qualifications_level"
            :value="scope.row.qualificationLevel"
          />
        </template>
      </el-table-column>
      <el-table-column label="不良记录" align="center" prop="badnessRecord">
        <template slot-scope="scope">
          {{ scope.row.badnessRecord }}次
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          {{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}
        </template>
      </el-table-column>
      <el-table-column label="所属组织" align="center" prop="department" />
      <el-table-column label="来源" align="center" prop="source" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['common:cooperator:edit']"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['common:cooperator:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改合作单位对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1400px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="基本信息" name="first">
          <el-form ref="form" :model="form" :rules="rules" label-width="150px">
            <el-row>
              <el-col :span="8">
                <el-form-item label="企业名称" prop="enterpriseName">
                  <el-input
                    v-model="form.enterpriseName"
                    placeholder="请输入企业名称"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8"
                ><el-form-item label="企业简称" prop="enterpriseAbbreviation">
                  <el-input
                    v-model="form.enterpriseAbbreviation"
                    placeholder="请输入企业简称"
                  /> </el-form-item
              ></el-col>
              <el-col :span="8"
                ><el-form-item label="上级单位" prop="deptId">
                  <treeselect
                    v-model="form.deptId"
                    :options="deptList"
                    :normalizer="normalizer"
                    :default-expand-level="100"
                    placeholder="请选择上级单位"
                  /> </el-form-item
              ></el-col>
              <el-col :span="8">
                <el-form-item
                  label="是否政府、军队、境外单位"
                  prop="governmentAgency"
                >
                  <el-radio-group v-model="form.governmentAgency">
                    <el-radio
                      v-for="dict in dict.type.sys_yes_no"
                      :key="dict.value"
                      :label="dict.value"
                      >{{ dict.label }}</el-radio
                    >
                  </el-radio-group>
                </el-form-item></el-col
              >
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="统一社会信用代码" prop="creditCode">
                  <el-input
                    v-model="form.creditCode"
                    placeholder="请输入统一社会信用代码"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="企业类型" prop="enterpriseType">
                  <el-select
                    style="width: 303px"
                    v-model="form.enterpriseType"
                    placeholder="请选择企业类型"
                  >
                    <el-option
                      v-for="dict in dict.type.common_enterprise_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select> </el-form-item
              ></el-col>
              <el-col :span="8"
                ><el-form-item label="资质等级" prop="qualificationLevel">
                  <el-select
                    style="width: 303px"
                    v-model="form.qualificationLevel"
                    placeholder="请选择资质等级"
                  >
                    <el-option
                      v-for="dict in dict.type.common_qualifications_level"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select> </el-form-item
              ></el-col>
            </el-row>
            <el-row>
              <el-col :span="8"
                ><el-form-item label="企业编码" prop="enterpriseCode">
                  <el-input
                    v-model="form.enterpriseCode"
                    placeholder="请输入企业编码"
                  /> </el-form-item
              ></el-col>
              <el-col :span="8"
                ><el-form-item label="企业性质" prop="enterpriseProperty">
                  <el-select
                    style="width: 303px"
                    v-model="form.enterpriseProperty"
                    placeholder="请选择企业性质"
                  >
                    <el-option
                      v-for="dict in dict.type.common_enterprise_character"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select> </el-form-item
              ></el-col>
              <el-col :span="8"
                ><el-form-item label="企业邮箱" prop="enterpriseMail">
                  <el-input
                    v-model="form.enterpriseMail"
                    placeholder="请输入企业邮箱"
                  /> </el-form-item
              ></el-col>
            </el-row>
            <el-row>
              <el-col :span="8"
                ><el-form-item label="电话" prop="phone">
                  <el-input
                    v-model="form.phone"
                    placeholder="请输入电话"
                  /> </el-form-item
              ></el-col>
              <el-col :span="8"
                ><el-form-item label="成立日期" prop="setUpDate">
                  <el-date-picker
                    style="width: 303px"
                    clearable
                    v-model="form.setUpDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择成立日期"
                  >
                  </el-date-picker> </el-form-item
              ></el-col>
              <el-col :span="8"
                ><el-form-item label="注册资金(万元)" prop="registerMoney">
                  <el-input
                    v-model="form.registerMoney"
                    placeholder="请输入注册资金(万元)"
                  /> </el-form-item
              ></el-col>
            </el-row>
            <el-row>
              <el-col :span="8"
                ><el-form-item label="评价状态" prop="evaluateStatus">
                  <el-select
                    style="width: 303px"
                    v-model="form.evaluateStatus"
                    placeholder="请选择评价状态"
                  >
                    <el-option
                      v-for="dict in dict.type.common_evaluate"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select> </el-form-item
              ></el-col>

              <el-col :span="8"
                ><el-form-item label="身份类型" prop="idType">
                  <el-select
                    v-model="form.idType"
                    placeholder="请选择身份类型"
                    style="width: 303px"
                  >
                    <el-option
                      v-for="dict in dict.type.common_id_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select> </el-form-item
              ></el-col>
            </el-row>
            <el-form-item label="地址" prop="address">
              <el-input
                v-model="form.address"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
            <el-form-item label="经营范围" prop="businessScope">
              <el-input
                v-model="form.businessScope"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="银行信息" name="second" :disabled="disabled">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAddBank"
            v-hasPermi="['common:bank:add']"
            >新增</el-button
          >
          <el-table v-loading="loading" :data="bankList">
            <el-table-column label="序号" align="center" prop="id" />
            <el-table-column
              label="银行账号"
              align="center"
              prop="bankAccount"
            />
            <el-table-column
              label="开户行名称"
              align="center"
              prop="openBankName"
            />
            <el-table-column
              label="分行名称"
              align="center"
              prop="branchName"
            />
            <el-table-column
              label="银联号"
              align="center"
              prop="unionpayAccount"
            />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="BankLookUpdate(scope.row)"
                  v-hasPermi="['common:bank:edit']"
                  >查看</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="BankhandleUpdate(scope.row)"
                  v-hasPermi="['common:bank:edit']"
                  >编辑</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleBankDelete(scope.row)"
                  v-hasPermi="['common:bank:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="Banktotal > 0"
            :total="Banktotal"
            :page.sync="queryBankParams.pageNum"
            :limit.sync="queryBankParams.pageSize"
            @pagination="getBankList"
          />
        </el-tab-pane>
        <el-tab-pane label="企业资质" name="third" :disabled="disabled">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            v-hasPermi="['common:qualification:add']"
            @click="handleAddQualification()"
            >新增</el-button
          >
          <el-table
            v-loading="loading"
            :data="qualificationList"
            @selection-change="handleSelectionChange"
          >
            <el-table-column label="序号" align="center" prop="id" />
            <el-table-column label="名称" align="center" prop="name" />
            <el-table-column label="编号" align="center" prop="code" />
            <el-table-column
              label="描述"
              align="center"
              prop="commonDescribe"
            />
            <el-table-column label="附件" align="center" prop="attachment" />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="LookQualificationUpdate(scope.row)"
                  v-hasPermi="['common:qualification:edit']"
                  >查看</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleQualificationUpdate(scope.row)"
                  v-hasPermi="['common:qualification:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleQualificationDelete(scope.row)"
                  v-hasPermi="['common:qualification:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="qualificationTotal > 0"
            :total="qualificationTotal"
            :page.sync="queryQualificationParams.pageNum"
            :limit.sync="queryQualificationParams.pageSize"
            @pagination="getQualificationList"
          />
        </el-tab-pane>
        <el-tab-pane label="不良记录" name="fourth" :disabled="disabled">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            v-hasPermi="['common:qualification:add']"
            @click="handleAddBadness()"
            >新增</el-button
          >
          <el-table v-loading="loading" :data="badnessList">
            <el-table-column label="序号" align="center" prop="id" />
            <el-table-column
              label="事件名称"
              align="center"
              prop="badnessName"
            />
            <el-table-column
              label="发生时间"
              align="center"
              prop="happenTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.happenTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column label="原因" align="center" prop="cause" />
            <el-table-column
              label="描述"
              align="center"
              prop="commonDescribe"
            />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="LookBadnessUpdate(scope.row)"
                  v-hasPermi="['common:badness:edit']"
                  >查看</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleBadnessUpdate(scope.row)"
                  v-hasPermi="['common:badness:edit']"
                  >修改</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleBadnessDelete(scope.row)"
                  v-hasPermi="['common:badness:remove']"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="badnessTotal > 0"
            :total="badnessTotal"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改合作单位-银行信息对话框 -->
    <el-dialog
      :title="Banktitle"
      :visible.sync="Bankopen"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="bankform"
        :model="form"
        :rules="Bankrules"
        label-width="100px"
      >
        <el-form-item label="银行名称" prop="bankName">
          <el-input
            :disabled="disabledBank"
            v-model="form.bankName"
            placeholder="请输入银行名称"
          />
        </el-form-item>
        <el-form-item label="银行账号" prop="bankAccount">
          <el-input
            :disabled="disabledBank"
            v-model="form.bankAccount"
            placeholder="请输入银行账号"
          />
        </el-form-item>
        <el-form-item label="开户行名称" prop="openBankName">
          <el-input
            :disabled="disabledBank"
            v-model="form.openBankName"
            placeholder="请输入开户行名称"
          />
        </el-form-item>
        <el-form-item label="分行名称" prop="branchName">
          <el-input
            :disabled="disabledBank"
            v-model="form.branchName"
            placeholder="请输入分行名称"
          />
        </el-form-item>
        <el-form-item label="银联号" prop="unionpayAccount">
          <el-input
            :disabled="disabledBank"
            v-model="form.unionpayAccount"
            placeholder="请输入银联号"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="BanksubmitForm">保存</el-button>
        <el-button @click="Bankcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改合作单位-企业资质对话框 -->
    <el-dialog
      :title="qualificationtitle"
      :visible.sync="qualificationopen"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="qualificationsubmitform"
        :model="form"
        :rules="qualificationrules"
        label-width="80px"
      >
        <el-form-item label="名称" prop="name">
          <el-input
            :disabled="disabledBank"
            v-model="form.name"
            placeholder="请输入名称"
          />
        </el-form-item>
        <el-form-item label="编号" prop="code">
          <el-input
            :disabled="disabledBank"
            v-model="form.code"
            placeholder="请输入编号"
          />
        </el-form-item>
        <el-form-item label="描述" prop="commonDescribe">
          <el-input
            :disabled="disabledBank"
            v-model="form.commonDescribe"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="附件" prop="attachment">
          <file-upload
            v-model="form.attachment"
            class="upload-demo"
            drag
            multiple
          >
          </file-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="QualificationsubmitForm"
          >确 定</el-button
        >
        <el-button @click="Qualificationcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改合作单位-不良记录对话框 -->
    <el-dialog
      :title="badnesstitle"
      :visible.sync="badnessopen"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="badnesssubmitform"
        :model="form"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="事件名称" prop="badnessName">
          <el-input
            :disabled="disabledBank"
            v-model="form.badnessName"
            placeholder="请输入事件名称"
          />
        </el-form-item>
        <el-form-item label="发生时间" prop="happenTime">
          <el-date-picker
            style="width: 380px"
            :disabled="disabledBank"
            clearable
            v-model="form.happenTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发生时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="原因" prop="cause">
          <el-input
            :disabled="disabledBank"
            v-model="form.cause"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="描述" prop="commonDescribe">
          <el-input
            :disabled="disabledBank"
            v-model="form.commonDescribe"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="BadnesssubmitForm">确 定</el-button>
        <el-button @click="Badnesscancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCooperator,
  getCooperator,
  delCooperator,
  addCooperator,
  updateCooperator,
} from "@/api/common/cooperator";
import {
  listBank,
  getBank,
  delBank,
  addBank,
  updateBank,
} from "@/api/common/bank";
import {
  listQualification,
  getQualification,
  delQualification,
  addQualification,
  updateQualification,
} from "@/api/common/qualification";
import {
  listBadness,
  getBadness,
  delBadness,
  addBadness,
  updateBadness,
} from "@/api/common/badness";
import { listDept } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Cooperator",
  dicts: [
    "list_type_status",
    "common_evaluate",
    "sys_yes_no",
    "common_id_type",
    "common_enterprise_type",
    "common_qualifications_level",
    "common_enterprise_character",
  ],
  components: { Treeselect },
  data() {
    return {
      //保存根ID
      CooperatorID: null,
      //默认选中标签页
      activeName: "first",
      //默认不可选
      disabled: true,
      disabledBank: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 树数据
      deptList: [],
      // 总条数
      total: 0,
      Banktotal: 0,
      qualificationTotal: 0,
      badnessTotal: 0,
      // 合作单位表格数据
      cooperatorList: [],
      // 合作单位-银行信息表格数据
      bankList: [],
      // 合作单位-企业资质表格数据
      qualificationList: [],
      // 合作单位-不良记录表格数据
      badnessList: [],
      // 弹出层标题
      title: "",
      Banktitle: "",
      qualificationtitle: "",
      badnesstitle: "",
      // 是否显示弹出层
      open: false,
      Bankopen: false,
      qualificationopen: false,
      badnessopen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseName: null,
        enterpriseAbbreviation: null,
        creditCode: null,
        enterpriseType: null,
        qualificationLevel: null,
        badnessRecord: null,
        department: null,
        source: null,
        governmentAgency: null,
        enterpriseCode: null,
        enterpriseProperty: null,
        enterpriseMail: null,
        phone: null,
        setUpDate: null,
        registerMoney: null,
        evaluateStatus: null,
        address: null,
        deptId: null,
        idType: null,
        businessScope: null,
        status: null,
      },
      queryBankParams: {
        pageNum: 1,
        pageSize: 10,
        cooperatorId: null,
        bankName: null,
        bankAccount: null,
        openBankName: null,
        branchName: null,
        unionpayAccount: null,
        status: null,
      },
      queryQualificationParams: {
        pageNum: 1,
        pageSize: 10,
        cooperatorId: null,
        name: null,
        code: null,
        commonDescribe: null,
        attachment: null,
        status: null,
      },
      queryBadnessParams: {
        pageNum: 1,
        pageSize: 10,
        cooperatorId: null,
        badnessName: null,
        happenTime: null,
        cause: null,
        commonDescribe: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        enterpriseName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" },
        ],
        creditCode: [
          {
            required: true,
            message: "统一社会信用代码不能为空",
            trigger: "blur",
          },
        ],
        enterpriseType: [
          { required: true, message: "企业类型不能为空", trigger: "change" },
        ],
        governmentAgency: [
          {
            required: true,
            message: "是否政府、军队、境外单位不能为空",
            trigger: "change",
          },
        ],
      },
      Bankrules: {
        bankName: [
          { required: true, message: "银行名称不能为空", trigger: "blur" },
        ],
        bankAccount: [
          { required: true, message: "银行账号不能为空", trigger: "blur" },
        ],
      },
      qualificationrules: {
        name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
    this.getTreeList();
  },
  methods: {
    //切换标签页
    handleClick(tab, event) {
      if (tab.index == 0 && this.disabled != true) {
        getCooperator(this.CooperatorID).then((response) => {
          this.disabled = false;
          this.form = response.data;
        });
      }
    },
    /** 查询合作单位列表 */
    getList() {
      this.loading = true;
      listCooperator(this.queryParams).then((response) => {
        this.cooperatorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询树列表 */
    getTreeList() {
      listDept().then((response) => {
        this.deptList = this.handleTree(response.data, "deptId");
      });
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children,
      };
    },
    /** 查询合作单位-银行信息列表 */
    getBankList(id) {
      this.loading = true;
      this.queryBankParams.cooperatorId = id;
      listBank(this.queryBankParams).then((response) => {
        this.bankList = response.rows;
        this.Banktotal = response.total;
        this.loading = false;
      });
    },
    /** 查询合作单位-企业资质列表 */
    getQualificationList(id) {
      this.loading = true;
      this.queryQualificationParams.cooperatorId = id;
      listQualification(this.queryQualificationParams).then((response) => {
        this.qualificationList = response.rows;
        this.qualificationTotal = response.total;
        this.loading = false;
      });
    },
    /** 查询合作单位-不良记录列表 */
    getBadnessList(id) {
      this.loading = true;
      this.queryBadnessParams.cooperatorId = id;
      listBadness(this.queryBadnessParams).then((response) => {
        this.badnessList = response.rows;
        this.badnessTotal = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        enterpriseName: null,
        enterpriseAbbreviation: null,
        creditCode: null,
        enterpriseType: null,
        qualificationLevel: null,
        badnessRecord: null,
        department: null,
        source: null,
        governmentAgency: null,
        enterpriseCode: null,
        enterpriseProperty: null,
        enterpriseMail: null,
        phone: null,
        setUpDate: null,
        registerMoney: null,
        evaluateStatus: null,
        address: null,
        deptId: null,
        idType: null,
        businessScope: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        cooperatorId: null,
        bankName: null,
        bankAccount: null,
        openBankName: null,
        branchName: null,
        unionpayAccount: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.activeName = "first";
      this.disabled = true;
      this.title = "合作单位一添加";
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      this.CooperatorID = id;
      getCooperator(id).then((response) => {
        this.disabled = false;
        this.form = response.data;
        this.open = true;
        this.title = "合作单位一编辑";
      });
      this.getBankList(id);
      this.getQualificationList(id);
      this.getBadnessList(id);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateCooperator(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCooperator(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除合作单位编号为"' + ids + '"的数据项？')
        .then(function () {
          return delCooperator(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "common/cooperator/export",
        {
          ...this.queryParams,
        },
        `cooperator_${new Date().getTime()}.xlsx`
      );
    },
    //------------银行模块------------------------------------------------------------------
    //新增
    handleAddBank() {
      this.reset();
      this.Bankopen = true;
      this.disabledBank = false;
      this.qualificationtitle = "新增合作单位-银行信息";
    },
    //保存
    BanksubmitForm() {
      this.$refs["bankform"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBank(this.form).then((response) => {
              if (this.disabledBank == true) {
                this.Bankopen = false;
                this.getBankList(this.CooperatorID);
              } else {
                this.$modal.msgSuccess("修改成功");
                this.Bankopen = false;
                this.getBankList(this.CooperatorID);
              }
            });
          } else {
            this.form.cooperatorId = this.CooperatorID;
            addBank(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.Bankopen = false;
              this.getBankList(this.CooperatorID);
            });
          }
        }
      });
    },
    //取消
    Bankcancel() {
      this.reset();
      this.Bankopen = false;
    },
    //查看
    BankLookUpdate(row) {
      this.reset();
      getBank(row.id).then((response) => {
        this.disabledBank = true;
        this.form = response.data;
        this.Bankopen = true;
        this.Banktitle = "合作单位一银行信息一查看";
      });
    },
    /** 编辑按钮操作 */
    BankhandleUpdate(row) {
      this.reset();
      const id = row.id;
      this.disabledBank = false;
      getBank(id).then((response) => {
        this.form = response.data;
        this.Bankopen = true;
        this.Banktitle = "合作单位一银行信息一编辑";
      });
    },
    /** 删除按钮操作 */
    handleBankDelete(row) {
      const ids = row.id;
      this.$modal
        .confirm('是否确认删除合作单位-银行信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBank(ids);
        })
        .then(() => {
          this.getBankList(this.CooperatorID);
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    //------------企业资质模块------------------------------------------------------------------
    //新增
    handleAddQualification() {
      this.reset();
      this.qualificationopen = true;
      this.disabledBank = false;
      this.qualificationtitle = "新增合作单位-企业资质";
    },
    //确定--提交
    QualificationsubmitForm() {
      this.$refs["qualificationsubmitform"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateQualification(this.form).then((response) => {
              if (this.disabledBank == true) {
                this.qualificationopen = false;
                this.getQualificationList(this.CooperatorID);
              } else {
                this.$modal.msgSuccess("修改成功");
                this.qualificationopen = false;
                this.getQualificationList(this.CooperatorID);
              }
            });
          } else {
            this.form.cooperatorId = this.CooperatorID;
            addQualification(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.qualificationopen = false;
              this.getQualificationList(this.CooperatorID);
            });
          }
        }
      });
    },
    //取消
    Qualificationcancel() {
      this.reset();
      this.qualificationopen = false;
    },
    //查看
    LookQualificationUpdate(row) {
      this.reset();
      const id = row.id;
      this.disabledBank = true;
      getQualification(id).then((response) => {
        this.form = response.data;
        this.qualificationopen = true;
        this.qualificationtitle = "查看合作单位-企业资质";
      });
    },
    //修改
    handleQualificationUpdate(row) {
      this.reset();
      const id = row.id;
      this.disabledBank = false;
      getQualification(id).then((response) => {
        this.form = response.data;
        this.qualificationopen = true;
        this.qualificationtitle = "修改合作单位-企业资质";
      });
    },
    //删除
    handleQualificationDelete(row) {
      const ids = row.id;
      this.$modal
        .confirm('是否确认删除合作单位-企业资质编号为"' + ids + '"的数据项？')
        .then(function () {
          return delQualification(ids);
        })
        .then(() => {
          this.getQualificationList(this.CooperatorID);
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    //------------不良记录模块------------------------------------------------------------------
    //新增
    handleAddBadness() {
      this.reset();
      this.badnessopen = true;
      this.disabledBank = false;
      this.badnesstitle = "新增合作单位-不良记录";
    },
    //确定--提交
    BadnesssubmitForm() {
      this.$refs["badnesssubmitform"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBadness(this.form).then((response) => {
              if (this.disabledBank == true) {
                this.badnessopen = false;
                this.getBadnessList(this.CooperatorID);
              } else {
                this.$modal.msgSuccess("修改成功");
                this.badnessopen = false;
                this.getBadnessList(this.CooperatorID);
              }
            });
          } else {
            this.form.cooperatorId = this.CooperatorID;
            addBadness(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.badnessopen = false;
              this.getBadnessList(this.CooperatorID);
            });
          }
        }
      });
    },
    //取消
    Badnesscancel() {
      this.reset();
      this.badnessopen = false;
    },
    //查看
    LookBadnessUpdate(row) {
      this.reset();
      const id = row.id;
      this.disabledBank = true;
      getBadness(id).then((response) => {
        this.form = response.data;
        this.badnessopen = true;
        this.badnesstitle = "查看合作单位-不良记录";
      });
    },
    //修改
    handleBadnessUpdate(row) {
      this.reset();
      const id = row.id;
      this.disabledBank = false;
      getBadness(id).then((response) => {
        this.form = response.data;
        this.badnessopen = true;
        this.badnesstitle = "修改合作单位-不良记录";
      });
    },
    //删除
    handleBadnessDelete(row) {
      const ids = row.id;
      this.$modal
        .confirm('是否确认删除合作单位-不良记录编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBadness(ids);
        })
        .then(() => {
          this.getBadnessList(this.CooperatorID);
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
